package com.example.sentinelstudy.service;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.stereotype.Service;

@Service
public class PersonService {

    @SentinelResource(value = "HelloWorld", blockHandler = "exceptionHandler", fallback = "helloFallback")
    public String getBody() {
        System.out.println("get success");
        return "get success";
    }

//    public String fallBack(BlockException blockException){
//        System.out.println("reject");
//        return "PersonService getBody reject fallback";
//    }

    // Fallback 函数，函数签名与原函数一致或加一个 Throwable 类型的参数.
    public String helloFallback(long s) {
        return String.format("Halooooo %d", s);
    }

    // Block 异常处理函数，参数最后多一个 BlockException，其余与原函数一致.
    public String exceptionHandler(long s, BlockException ex) {
        // Do some log here.
        ex.printStackTrace();
        return "Oops, error occurred at " + s;
    }
}
